import { useSelector } from 'react-redux/es/hooks/useSelector'
import { StateType } from '../store'
import { ComponentStateType } from '../store/componentsReducer'

export default function useGetComponentInfo() {
  const components = useSelector<StateType>(state => state.components.present) as ComponentStateType

  const { componentList = [], selectedId, copiedComponent } = components

  const selectedComponent = componentList.find(c => c.fe_id === selectedId)

  return { componentList, selectedId, selectedComponent, copiedComponent }
}
